package test_junit_merchant.ManageMerchant;

import org.openqa.selenium.By;
import util.BaseDriver;

/**
 * Created by Eric on 2018/1/30.
 * 商户-门店新建
 */
public class Shop extends BaseDriver {

    private static Shop ns = new Shop();
    public static Shop getInstance(){
        return ns;
    }

    private Shop() {

    }

    /**
     *
     * @param storeName 仓库全名
     * @param shortName 门店简称
     * @param phoneNum  负责人手机号码
     * @param responsName 负责人姓名
     * @return
     */
    public void add(String storeName, String shortName, String phoneNum, String responsName) throws InterruptedException {
        try {
            System.out.println("进入门店新增测试");

            driver.switchTo().frame(driver.findElement(By.xpath("//div[@id='page-wrapper']/div[2]/iframe[2]")));

            // 新增 按钮
            driver.findElement(By.xpath("//button[@onclick='add()']")).click();
            System.out.println("点击新增");
            Thread.sleep(2000);

            driver.switchTo().frame(0);

            // 门店全称
            driver.findElement(By.name("name")).sendKeys(storeName);
            System.out.println("输入门店全称：" + storeName);

            // 门店简称
            driver.findElement(By.name("nickname")).sendKeys(shortName);
            System.out.println("输入门店简称：" + shortName);

            // 地址
            String address = "北京周口店";
            driver.findElement(By.name("address")).sendKeys(address);
            System.out.println("输入详细地址：" + address);

            // 负责人手机号码
            driver.findElement(By.name("phone")).sendKeys(phoneNum);
            System.out.println("输入负责人手机号码：" + phoneNum);
            Thread.sleep(1000);

            // 负责人姓名
            driver.findElement(By.id("realName")).sendKeys(responsName);
            System.out.println("输入负责人姓名：" + responsName);

            // 省份
            driver.findElement(By.xpath("//select[@name='province.id']/option[2]")).click();
            Thread.sleep(1000);

            // 城市
            driver.findElement(By.xpath("//select[@name='city.id']/option[2]")).click();
            Thread.sleep(1000);

            // 区域
            driver.findElement(By.xpath("//select[@name='district.id']/option[2]")).click();
            Thread.sleep(1000);

            // 资质规模
            driver.findElement(By.xpath("//select[@name='businessRange']/option[2]")).click();
            Thread.sleep(1000);

            driver.switchTo().parentFrame();

            // 确定 按钮
            driver.findElement(By.linkText("确定")).click();
            Thread.sleep(3000);

            // 继续开通 按钮
            driver.findElement(By.linkText("继续开通")).click();
            Thread.sleep(2000);

            // 取消 按钮
            driver.findElement(By.linkText("取消")).click();
            System.out.println("添加门店成功");
        } catch (Error error) {
            System.err.println("添加门店失败");
            error.printStackTrace();
            // shot
        }
    }
}
